package Server.ExtComponents.MinaEngine.config;

import org.aeonbits.owner.ConfigFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author :石头哥哥<br/>
 *         Project:FrameServer1.0
 *         Date: 13-5-19
 *         Time: 下午5:00
 */
public class MServerConfig {
    private static final Logger LOG = LoggerFactory.getLogger(MServerConfig.class);  //logger

    public  static  boolean DEBUG=false;
    public static  int GameServerPort=0;//server port
    public static  int maxConnection=0;//最大连接数
    public static final int NioProcessor=Runtime.getRuntime().availableProcessors()+1; //NioProcessor处理IO线程数量
    public static  int SESSION_IDLE=0;

    public static int DEFAULT_KEEPALIVE_TIME=30;
    public static int corePoolSize=3;

    public static int lengthFieldLength=2;//pack length


    /**
     * 初始化mina服务器基本配置
     */
    public boolean IntiConfig()throws Exception{
        boolean status=false;
        try {
            BaseConfig baseConfig= ConfigFactory.create(BaseConfig.class);
            DEBUG=baseConfig.DEBUG();
            GameServerPort=baseConfig.GameServerPort();
            maxConnection=baseConfig.maxConnection();
            SESSION_IDLE=baseConfig.SESSION_IDLE();
            DEFAULT_KEEPALIVE_TIME=baseConfig.DEFAULT_KEEPALIVE_TIME();
            corePoolSize=baseConfig.corePoolSize();
            lengthFieldLength=baseConfig.lengthFieldLength();
            status=true;
        }catch (Exception e){
            LOG.error("inti mina base config is error!",e);
        }
        return status;
    }

}
